import { regularEmail, regularPhoneNumber } from '../../../utils/regular';

/**
 * 创建用户表单验证
 * @param {object} form 表单数据
 */
export function validateCreateForm(form) {
  if (!form.name) return '请填写账户名';
  if (!form.password) return '请设定密码';
  if (form.password.length < 6) return '密码长度不得小于6位';
  if (!form.roleUuidList || !form.roleUuidList.length) return '请选择角色';
  if (form.email && !regularEmail(form.email)) return '请输入正确的邮箱';
  if (form.mobile && !regularPhoneNumber(form.mobile)) return '请输入正确的手机号码';
  if (!form.organizationIdList || !form.organizationIdList.length) return '请选择组织';
}

/**
 * 编辑用户表单验证
 * @param {object} form 表单数据
 */
export function validateEditForm(form) {
  if (!form.name) return '请填写账户名';
  if (form.email && !regularEmail(form.email)) return '请输入正确的邮箱';
  if (form.mobile && !regularPhoneNumber(form.mobile)) return '请输入正确的手机号码';
  if (!form.organizationIdList || !form.organizationIdList.length) return '请选择组织';
}
